<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Message/index')}">发送消息列表</a></li>
        <li><a href="{:url('Message/sendToParents')}">给家长发送通知</a></li>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('Message/index')}">

        <label class="col-md-3 col-xs-6 form-group">
            关键字:
            <input type="text" class="form-control" name="keywords"
                   value="{$param.keywords|default=''}" placeholder="请输入关键字">
        </label>

        <label class="col-md-3 col-xs-6 form-group" style="margin-bottom: 15px;">
            发送者:
            <input type="text" class="form-control" name="sender_name"
                   value="{$param.sender_name|default=''}" placeholder="请输入发送者姓名">
        </label>

        <label class="form-group col-md-6 col-xs-9">
            发送时间:&nbsp;&nbsp;
            <input type="text" class="form-control" name="start" value="{$param.start|default=''}"
                   autocomplete="off"> -
            <input type="text" class="form-control" name="end" value="{$param.end|default=''}"
                   autocomplete="off">
        </label>

        <label class="col-md-offset-8 col-md-4 col-xs-3 form-group">
            <input type="submit" class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('Message/index')}">清空</a>
        </label>
    </form>

    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th>编号</th>
                <th>发送者</th>
                <th>接收者</th>
                <th>主题</th>
                <th>内容</th>
                <th>发送时间</th>
            </tr>
            </thead>
            <notempty name="messages">
                <foreach name="messages" item="vo">
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.user_name}</td>
                        <td>{$vo.receive_name}</td>
                        <td>{$vo.subject}</td>
                        <td>{$vo.content}</td>
                        <td>{:date('Y-m-d H:i:s',$vo.create_time)}</td>
                    </tr>
                </foreach>
            </notempty>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    $('input[name="start"]').datepicker();
    $('input[name="end"]').datepicker();

    $('body').on('click','.msg_status',function () {
        var $this=$(this);
        var msgId=$this.parents('tr').find('td:first').text();
        //ajax更改状态+获取内容
        $.ajax({
            url:"{:url('Message/ajaxRead')}",
            type:'post',
            dataType:'json',
            data:{"msg_id":msgId},
            success:function(jsonData){
                var html = '<i class="fa fa-envelope-open-o fa-fw"></i>';
                if(jsonData.code == 1){
                    $this.removeClass('msg_status');
                    html += jsonData.data;
                }
                $this.html(html);
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });

    });
</script>
</body>
